<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" >
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">

    <title>自动气象站数据实时信息发布系统</title>

    <meta name="keywords" content="">
    <meta name="description" content="">

    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->

    <link rel="shortcut icon" href="favicon.ico">
    <link href="css/bootstrap.min.css?v=3.3.6" th:href="@{/css/bootstrap.min.css?v=3.3.6}" rel="stylesheet">
    <link href="css/font-awesome.min.css?v=4.4.0" th:href="@{/css/font-awesome.min.css?v=4.4.0}" rel="stylesheet">
    <link href="css/animate.css" th:href="@{/css/animate.css}" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" th:href="@{/css/style.css?v=4.1.0}" rel="stylesheet">

    <!-- 全局js -->
    <script src="js/jquery.min.js?v=2.1.4" th:src="@{/js/jquery.min.js?v=2.1.4}"></script>
    <script src="js/bootstrap.min.js?v=3.3.6" th:src="@{/js/bootstrap.min.js?v=3.3.6}" ></script>
    <script src="js/plugins/metisMenu/jquery.metisMenu.js" th:src="@{/js/plugins/metisMenu/jquery.metisMenu.js}"></script>
    <script src="js/plugins/slimscroll/jquery.slimscroll.min.js" th:src="@{/js/plugins/slimscroll/jquery.slimscroll.min.js}"></script>
    <script src="js/plugins/layer/layer.min.js" th:src="@{/js/plugins/layer/layer.min.js}" ></script>
    <!-- 第三方插件 -->
    <script src="js/plugins/pace/pace.min.js" th:src="@{/js/plugins/pace/pace.min.js}"></script>
    <script src="../static/js/jquery-ui.custom.min.js" th:src="@{/js/jquery-ui.custom.min.js}" ></script>
    <script src="../static/js/jquery-ui-1.10.4.min.js" th:src="@{/js/jquery-ui-1.10.4.min.js}"></script>
    <!-- 自定义js -->
    <script src="js/hAdmin.js?v=4.1.0" th:src="@{/js/hAdmin.js?v=4.1.0}"></script>
    <!--    <script type="text/javascript" src="js/index.js" th:src="@{/js/index.js}"></script>-->


</head>

<body class="fixed-sidebar full-height-layout gray-bg" style="overflow:hidden">
<div id="wrapper">
    <!--左侧导航开始-->
    <div th:replace="include/left_navigation_bar::left_navigation_bar_style"></div>
    <!--左侧导航结束-->
    <!--右侧部分开始-->
    <div id="page-wrapper" class="gray-bg dashbard-1">
        <div th:replace="include/head::head_style"></div>
        <div class="row J_mainContent" id="content-main">
            <form class="form-horizontal m-t" id="signupForm2">
                <input type="hidden" name="id" id="up_user_id" th:value="${user.id}" >
                <div class="form-group">
                    <label class="col-sm-3 control-label">账号</label>
                    <div class="col-sm-3">
                        <input id="up_user_name" disabled name="name" th:value="${user.name}" class="form-control" type="text" onchange="verificationName()" >
                        <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 账号不可修改</span>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-3 control-label">昵称</label>
                    <div class="col-sm-3">
                        <input id="up_user_nick_name" th:value="${user.nickName}" name="nickName" class="form-control" type="text" >
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-3 control-label">邮箱：</label>
                    <div class="col-sm-3">
                        <input id="up_user_email" th:value="${user.email}" name="email" class="form-control" type="email">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-3 control-label">手机：</label>
                    <div class="col-sm-3">
                        <input id="up_user_phone" name="phone" th:value="${user.phone}" class="form-control" type="text">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">描述：</label>
                    <div class="col-sm-3">
                        <input id="up_user_desc" name="desc" th:value="${user.desc}" class="form-control" type="text" >
                    </div>
                </div>


                <div class="form-group">
                    <label class="col-sm-3 control-label">密码：</label>
                    <div class="col-sm-3">
                        <input id="up_user_password" name="password" class="form-control" type="password">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">确认密码：</label>
                    <div class="col-sm-3">
                        <input id="up_user_password2" class="form-control" type="password">
                        <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 请再次输入您的密码</span>
                    </div>
                </div>
                
                <div class="form-group">
                    <div class="col-sm-8 col-sm-offset-3">
                        <button class="btn btn-primary" type="button" onclick="updateUserSubmit()">保存</button>
                        <button type="button" id="up_close_button" onclick="closeButton()" class="btn btn-white" data-dismiss="modal">关闭</button>
                    </div>
                </div>

            </form>
        </div>
    </div>
    <!--右侧部分结束-->
</div>

<script>
    //校验 账号
    function verificationName(){
        let name = $("#up_user_name").val();
        if (!getVal(name)){
            return;
        }
        let url = "/user/verificationName?name="+name;
        $.get(url,function (resp){
            let code = resp.code;
            if (code == 200){
                return true;
            }else {
                $("#up_user_name").val("");
                parent.layer.msg("账号已存在，请重新输入！");
                return false;
            }
        });
    }

    function closeButton(){
        window.location.href = "/login";
    }

    function getVal(v) {
        let a = !(!v);
        console.log("getVal:" + v + ",a:" + a);
        return a;
    }

    function updateUserSubmit(){
        let id = $("#up_user_id").val();
        let name = $("#up_user_name").val();
        let nickName = $("#up_user_nick_name").val();
        let phone = $("#up_user_phone").val();
        let email = $("#up_user_email").val();
        let desc = $("#up_user_desc").val();
        let password = null;
        let status = null;

        let up_user_password = $("#up_user_password").val();
        let up_user_password2 = $("#up_user_password2").val();
        if (up_user_password != null && up_user_password != undefined){
            if (up_user_password2 != null && up_user_password2 != undefined){
                if (up_user_password == up_user_password2){
                    password = up_user_password;
                }else {
                    parent.layer.msg("两次密码不一样，请重新输入密码！");

                    return;
                }
            }else {
                parent.layer.msg("请再次输入密码!");

                return;
            }
        }

        let data = {};
        data.id = id;
        if (getVal(name)){
            data.name = name;
        }else {
            parent.layer.msg("账号不能为空");
            return;
        }
        if (getVal(nickName)){
            data.nickName = nickName;
        }else {
            parent.layer.msg("昵称不能为空");
            return;
        }
        data.phone = phone;
        data.email = email;
        data.desc = desc;
        if (getVal(password)){
            data.password = password;
        }

        $.post("/user/update",data,function (resp){
            if (resp.code == 200){
                parent.layer.msg("保存成功")
                setTimeout(function(){
                    window.location.reload();
                },1*1000);
            }
        });

    }
</script>
<div style="text-align:center;"></div>
</body>

</html>
